package com.maysham.tripod.service.impl;

import com.maysham.tripod.dao.CodeBaseDao;
import com.maysham.tripod.dto.CodeBaseRequest;
import com.maysham.tripod.dto.CodeSource;
import com.maysham.tripod.model.CodeBase;
import com.maysham.tripod.service.CodeBaseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
@Slf4j
public class CodeBaseServiceImpl implements CodeBaseService {
    @Resource
    private CodeBaseDao codeBaseDao;

    @Override
    public CodeBase create(CodeBaseRequest request) {
        CodeBase codeBase = new CodeBase();
        codeBase.setUrl(request.getUrl());
        codeBase.setName(request.getName());
        CodeSource source = new CodeSource();
        source.setPassword(request.getPassword());
        source.setUsername(request.getPassword());
        source.setType(request.getType());
        codeBase.setSource(source);
        return codeBaseDao.save(codeBase);
    }
}
